import type {
  ConsultOrderItem,
  ConsultOrderListParams,
  ConsultOrderPage,
  ConsultOrderPreData,
  ConsultOrderPreParams,
  DoctorPage,
  FollowType,
  Image,
  KnowledgePage,
  KnowledgeParams,
  PageParams,
  PatientConsult,
  TopDep
} from '@/types/consult'
import { request } from '@/utils/request'
/**
 * 获取首页-百科文章-列表数据
 */
export const getKnowledgePage = (params: KnowledgeParams) => {
  return request<KnowledgePage>('patient/home/knowledge', 'GET', params)
}
/**
 * 获取首页-推荐-获取关注医生
 */
export const getDoctorPage = (params: PageParams) => {
  return request<DoctorPage>('home/page/doc', 'GET', params)
}
/**
 * 首页-推荐-关注医生
 */
export const followDoctor = (id: string, type: FollowType = 'doc') => {
  return request<{ id: string }>('like', 'POST', { id, type })
}

/**
 * 获取全部科室
 */
export const getAllDep = () => request<TopDep[]>('/dep/all')

/* 上传图片 */
export const uploadImg = (file: File) => {
  const fd = new FormData()
  fd.append('file', file) // 设置参数名 和 类型
  return request<Image>('/upload', 'POST', fd)
}

// 拉取预支付订单信息
export const getConsultOrderPre = (params: ConsultOrderPreParams) =>
  request<ConsultOrderPreData>('/patient/consult/order/pre', 'GET', params)

// 生成订单id
export const createConsultOrder = (data: PatientConsult) =>
  request<{ id: string }>('/patient/consult/order', 'POST', data)

// 支付地址
const getConsultPayReturnUrl = (data: {
  paymentMethod: 0 | 1
  orderId: string
  payCallback: string
}) => {
  return request<{ payUrl: string }>('/patient/consult/pay', 'POST', data)
}
export { getConsultPayReturnUrl }

// 获取问诊(药品)订单详情
export const getConsultOrderDetail = (orderId: string) =>
  request<ConsultOrderItem>('/patient/consult/order/detail', 'GET', { orderId })

// 查看处方图片
export const getPrescription = (id: string) =>
  request<{ url: string }>(`/patient/consult/prescription/${id}`, 'GET', {})

// 提交(表单)评价(医生)
export const submitFormEvaluation = (data: {
  docId: string
  orderId: string
  score: number
  content: string
  anonymousFlag: 0 | 1
}) => request<{ id: string }>('/patient/order/evaluate', 'post', data)

// 获取订单列表
export const getConsultOrderList = (params: ConsultOrderListParams) =>
  request<ConsultOrderPage>('/patient/consult/order/list', 'GET', params)

// 取消 问诊支付订单
export const CancelOrder = (id: string) =>
  request<{}>(`/patient/order/cancel/${id}`, 'put')
// 删除 问诊支付订单
export const DeleteOrder = (id: string) =>
  request<{}>(`/patient/order/${id}`, 'delete')
